import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// 路由守卫
router.beforeEach((to, from, next) => {
    // 从cookies里查找存储内容
    const getCookie = (cname) => {   // 参数为存储名
        var name = cname + "=";
        var ca = document.cookie.split(';');
        // console.log(ca, 'ca');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) return decodeURIComponent(c.substring(name.length, c.length));
        }
        return "";
    };
    // console.log(to)
    if (getCookie('token') === '' && to.name !== 'Login' && to.name !== 'Head') {    //未登入
        // console.log(123)
        return next({ name: 'Login' })
    } else if (to.name === 'Login' && getCookie('token') !== '') {
        // console.log(123)
        next({ name: 'HomeEstateManagementFirst' })
    }
    next();
})



createApp(App).use(store).use(router).mount('#app')
